/***********************************************************************
 * Module:  Societe.java
 * Author:  Chris
 * Purpose: Defines the Class Societe
 ***********************************************************************/

package modele;

import java.util.*;

/** @pdOid a49dbdc3-b6f3-478f-8f99-61fdebcf2ca3 */
public class Societe {
   /** @pdRoleInfo migr=no name=Entrepot assc=association5 coll=java.util.Collection impl=java.util.HashSet mult=0..* */
   public ArrayList<Entrepot> entrepot;
   /** @pdRoleInfo migr=no name=Employe assc=association11 coll=java.util.Collection impl=java.util.HashSet mult=0..* */
   public ArrayList<Employe> employe;
   
   public ArrayList<Client> lesClients;
   public ArrayList<Fidele> lesClientsFidele;
   private static Societe _instance=null;
  
   public Societe(){
	   this.lesClients= new ArrayList<Client>();
	   this.lesClientsFidele= new ArrayList<Fidele>();
	   this.entrepot= new ArrayList<Entrepot>();
	   this.employe= new ArrayList<Employe>();
   }
   public static synchronized Societe getInstance(){
	   if(_instance==null){
		   _instance = new Societe();
		   
	   }
	   return _instance;
   }
   /** @param dateDebut 
    * @param dateFin
    * @pdOid 21c60458-1ecf-4956-8f91-97644b7fd8f2 */
   public float calculerCA(Date dateDebut, Date dateFin) {
      // TODO: implement
	   float chiffre = 0;
	   for(int i = 0; i<entrepot.size();i++){
		   for(int j=0;j<entrepot.get(i).expedition.size();j++){
			   if((entrepot.get(i).expedition.get(j).getDateLivraison().after(dateDebut))&&
					   (entrepot.get(i).expedition.get(j).getDateLivraison().before(dateFin))){
				   chiffre+= entrepot.get(i).expedition.get(j).prixTotal;
			   }
			   
		   }		   
	   }
	   
      return chiffre;
   }
   
   
   /** @pdGenerated default getter */
   public java.util.Collection<Entrepot> getEntrepot() {
      if (entrepot == null)
         entrepot = new ArrayList<Entrepot>();
      return entrepot;
   }
   
   /** @pdGenerated default iterator getter */
   public java.util.Iterator getIteratorEntrepot() {
      if (entrepot == null)
         entrepot = new ArrayList<Entrepot>();
      return entrepot.iterator();
   }
   
   /** @pdGenerated default setter
     * @param newEntrepot */
   public void setEntrepot(java.util.Collection<Entrepot> newEntrepot) {
      removeAllEntrepot();
      for (java.util.Iterator iter = newEntrepot.iterator(); iter.hasNext();)
         addEntrepot((Entrepot)iter.next());
   }
   
   /** @pdGenerated default add
     * @param newEntrepot */
   public void addEntrepot(Entrepot newEntrepot) {
      if (newEntrepot == null)
         return;
      if (this.entrepot == null)
         this.entrepot = new ArrayList<Entrepot>();
      if (!this.entrepot.contains(newEntrepot))
         this.entrepot.add(newEntrepot);
   }
   
   /** @pdGenerated default remove
     * @param oldEntrepot */
   public void removeEntrepot(Entrepot oldEntrepot) {
      if (oldEntrepot == null)
         return;
      if (this.entrepot != null)
         if (this.entrepot.contains(oldEntrepot))
            this.entrepot.remove(oldEntrepot);
   }
   
   /** @pdGenerated default removeAll */
   public void removeAllEntrepot() {
      if (entrepot != null)
         entrepot.clear();
   }
   /** @pdGenerated default getter */
   public java.util.Collection<Employe> getEmploye() {
      if (employe == null)
         employe = new ArrayList<Employe>();
      return employe;
   }
   
   /** @pdGenerated default iterator getter */
   public java.util.Iterator getIteratorEmploye() {
      if (employe == null)
         employe = new ArrayList<Employe>();
      return employe.iterator();
   }
   
   /** @pdGenerated default setter
     * @param newEmploye */
   public void setEmploye(ArrayList<Employe> newEmploye) {
      removeAllEmploye();
      for (java.util.Iterator iter = newEmploye.iterator(); iter.hasNext();)
         addEmploye((Employe)iter.next());
   }
   
   /** @pdGenerated default add
     * @param newEmploye */
   public void addEmploye(Employe newEmploye) {
      if (newEmploye == null)
         return;
      if (this.employe == null)
         this.employe = new ArrayList<Employe>();
      if (!this.employe.contains(newEmploye))
         this.employe.add(newEmploye);
   }
   
   /** @pdGenerated default remove
     * @param oldEmploye */
   public void removeEmploye(Employe oldEmploye) {
      if (oldEmploye == null)
         return;
      if (this.employe != null)
         if (this.employe.contains(oldEmploye))
            this.employe.remove(oldEmploye);
   }
   
   /** @pdGenerated default removeAll */
   public void removeAllEmploye() {
      if (employe != null)
         employe.clear();
   }

}